'''
@Project ：python-study
@File    ：8.8数据运算：分值区间.py
@IDE     ：PyCharm
@Author  ：SUNLIN
@Date    ：2025/3/11 15:25:37
'''

import pandas as pd
import numpy as np

pd.set_option('display.max_rows', None)

# 读取数据
data = pd.read_excel("../doc/datasource/C8-8.5-movie-data-clean.xlsx")
# 1.知道当前区间的最大值和最小值
print(data['average'].describe())
# 2.获取各评分类别数据
x = 2.2
rate_list = []
while x <= 9.7:
    rate_list.append(x)
    x += 0.1
    x = x.__round__(1)
print(rate_list)

# 3.依次进行统计: for每一行/单元格，判断数据-label，rate统计df对应tj + 1
data_rate_tj = pd.DataFrame(np.zeros([len(rate_list), 1]), index=rate_list, columns=['统计'])

# 遍历评分列表
for r in data['average']:
    for r1 in rate_list:
        if (r == r1):
            data_rate_tj.loc[r1, '统计'] += 1
print(data_rate_tj)
